package com.fz.main.dao;

import com.fz.entity.Stu;
import com.fz.entity.Student;
import com.fz.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.sql.Connection;
import java.util.List;


/**
 * Created by webrx on 2018-01-18.
 */
public class Demo {
    private final static Logger logger = LoggerFactory.getLogger(Demo.class);
    public static void main(String[] args) throws IOException {
        //logger.info("hello");
        //logger.debug("debug....");
        //logger.error("数据库链接错误啦....");
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
        SqlSession session = sf.openSession();
        StudentMapper sdao = session.getMapper(StudentMapper.class);
        //System.out.println(sdao.query());

        Connection conn = session.getConnection();
        System.out.println(conn);

        List<Student> list = sdao.query();
        for(Student st : list){
            System.out.println(st.getSname());
        }

        List<Stu> stus = sdao.show();
        for(Stu stt : stus){
            logger.info(stt.toString());
        }

        //logger.info("查询结果有："+ list.size() +"条");





    }
}
